package cuppics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;

public class Prj29 {

	/**
	 * 
	 */
	@Test
	public void test() {
		System.out.println(Calculator.calculate());
	}

	public static class Calculator {

		public static int calculate() {

			Set<Sequence> data = new HashSet<Sequence>();

			IntegerDivisor div = new IntegerDivisor();
			for (int a = 2; a <= 100; a++) {
				for (int b = 2; b <= 100; b++) {
					div.divisor(a);
					Sequence sq = new Sequence();
					copyMap(sq, div.primeMap, b);
					data.add(sq);
					div.clear();

				}
			}

			return data.size();

		}

		private static void copyMap(Sequence sq, Map<Long, Integer> primeMap, int b) {

			for (Entry<Long, Integer> entry : primeMap.entrySet()) {
				sq.map.put(entry.getKey().intValue(), entry.getValue() * b);
			}

		}

	}

	public static class Sequence {

		public Map<Integer, Integer> map = new HashMap<Integer, Integer>();

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#hashCode()
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((map == null) ? 0 : map.hashCode());
			return result;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#equals(java.lang.Object)
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (!(obj instanceof Sequence)) {
				return false;
			}
			Sequence other = (Sequence) obj;
			if (map == null) {
				if (other.map != null) {
					return false;
				}
			} else if (!map.equals(other.map)) {
				return false;
			}
			return true;
		}

	}

	/**
	 * 因子分解
	 * 
	 * @author 1440
	 * 
	 */
	public static class IntegerDivisor {

		public Map<Long, Integer> primeMap = new HashMap<Long, Integer>();
		public List<Long> primeList = new ArrayList<Long>();

		public void clear() {
			primeMap.clear();
			primeList.clear();
		}

		public void divisor(long num) {

			if (num <= 1)
				return;

			long prime = getPrime(
					num,
					primeList.size() == 0 ? 2
							: primeList.get(primeList.size() - 1));
			if (prime < 0) {
				primeMap.put(num, 1);
				primeList.add(num);
				return;
			} else {

				primeList.add(prime);
				int count = 0;
				do {

					count += 1;
					num = num / prime;
				} while (num % prime == 0);

				primeMap.put(prime, count);

				divisor(num);

			}

		}

		private long getPrime(long num, long start) {

			for (long i = start; i <= Math.sqrt(num); i++) {
				if (num % i == 0) {
					return i;
				}
			}
			return -1;
		}

		@Override
		public String toString() {

			return print_Map(this.primeMap);
		}

		public Long getLargestPrime() {
			return primeList.get(primeList.size() - 1);
		}

	}

	public static String print_Map(Map<?, ?> primeMap) {
		StringBuilder sb = new StringBuilder();
		for (Entry<?, ?> entry : primeMap.entrySet()) {
			sb.append(entry.getKey().toString() + "="
					+ entry.getValue().toString() + "\n");
		}
		return sb.toString();
	}

	public static void print_List(List<Integer> list) {
		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i) + ",");
		}
		System.out.println();
	}
}
